package UI;

import java.util.Vector;

import data_management.InvDBManager;
import junit.framework.TestCase;

public class SaleInterfaceTest extends TestCase {
	
	/**
	 * This test ensures that a created sale interface is valid.
	 */
	public void testInitialize() {
		
		InvDBManager.getInstance().initializeDatabase();
		SaleInterface sale = new SaleInterface();
		sale.initialize();
		
		assertTrue(sale.searchField != null);
		assertTrue(sale.search != null);
		assertTrue(sale.columnFilter != null);
		assertTrue(sale.sale != null);
		assertTrue(sale.toSale != null);
		assertTrue(sale.toInv != null);
		assertTrue(sale.checkout != null);
		assertTrue(sale.clearSale != null);
		assertTrue(sale.subtotal != null);
		assertTrue(sale.tax != null);
		assertTrue(sale.total != null);
		
		InvDBManager.getInstance().cleanUp();
		
	}
	
	/**
	 * This test ensures that the displayed total is correct
	 */
	public void testRetotal() {
		
		InvDBManager.getInstance().initializeDatabase();
		
		SaleInterface sale = new SaleInterface();
		sale.initialize();
		
		Vector<String> tRow = new Vector<String>();
			tRow.add("Corn");
			tRow.add("3.5");
			tRow.add("2573672");
		sale.sale.getModel().addRow(tRow);
		sale.retotal();
		
		assertTrue(Double.valueOf(sale.change.getText()) == Double.valueOf(sale.tendered.getText()) - Double.valueOf(sale.total.getText()));
		
		InvDBManager.getInstance().cleanUp();
		
	}
}
